package com.ikas.ai.server.module.data.dorisDao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ikas.ai.server.module.data.model.doris.DorisYxData;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 工况转换流程实例表
 *
 * @author hu.bowei
 * @email hu.bowei@ikasinfo.com
 * @date 2023-05-06 17:12:07
 */
public interface DorisYxDataDao extends BaseMapper<DorisYxData> {

    @Select("SELECT mete_id,machine_no,mete_code,mete_name,value,model_use,generate_time,report_time,update_time,create_time\n" +
            "FROM (\n" +
            "  SELECT *,\n" +
            "         ROW_NUMBER() OVER (PARTITION BY mete_id ORDER BY report_time DESC) AS row_num\n" +
            "  FROM t_data_yx\n" +
            "  WHERE mete_code LIKE CONCAT('%', #{equipmentCode}, '%') AND machine_no = #{machineNo} AND model_use = 1 AND mete_code IS NOT NULL\n" +
            ") AS ranked\n" +
            "WHERE row_num = 1\n")
    List<DorisYxData> getYxDataInMaxReportTimeByWindow(@Param("machineNo") String machineNo, @Param("equipmentCode") String equipmentCode);

    @Select("SELECT mete_code,mete_id,report_time,mete_name,value\n" +
            "FROM (\n" +
            "  SELECT *,\n" +
            "         ROW_NUMBER() OVER (PARTITION BY mete_id ORDER BY report_time DESC) AS row_num\n" +
            "  FROM t_data_yx\n" +
            "  WHERE mete_code LIKE CONCAT('%', #{equipmentCode}, '%') AND machine_no = #{machineNo} AND model_use = 1 AND mete_code IS NOT NULL\n" +
            ") AS ranked\n" +
            "WHERE row_num = 1\n")
    List<DorisYxData> getLessColumnForDownPut(@Param("machineNo") String machineNo, @Param("equipmentCode") String equipmentCode);
}
